﻿using Batman.Jianbei.Forum.Core.Consts;
using System.Linq;
using System.Security.Claims;

namespace Batman.Jianbei.Forum
{
    public static class UserIdentityExtension
    {
        /// <summary>
        /// 获取登录者用户ID
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static string GetUserId(this ClaimsPrincipal user)
        {
            string userId = user.Claims.Where(c => c.Type == UserClaims.UserId).Select(x => x.Value).FirstOrDefault();
            return userId;
        }

        /// <summary>
        /// 获取微信用户ID
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static string GetWxUserId(this ClaimsPrincipal user)
        {
            string wxUserId = user.Claims.Where(c => c.Type == UserClaims.WxUserId).Select(x => x.Value).FirstOrDefault();
            return wxUserId;
        }
    }
}
